package com.sky.controller.admin;

import com.sky.dto.GoodDTO;
import com.sky.dto.GoodPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.GoodService;
import com.sky.vo.GoodVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品相关
 */
@RestController
@RequestMapping("/admin/good")
@Api(tags = "商品相关接口")
@Slf4j
public class GoodController {

    @Autowired
    private GoodService goodService;

    /**
     * 新增商品
     *
     * @param goodDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增商品")
    public Result save(@RequestBody GoodDTO goodDTO) {
        log.info("新增商品：{}", goodDTO);
        goodService.save(goodDTO);//后绪步骤开发
        return Result.success();
    }

    /**
     * 商品分页查询
     *
     * @param goodPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("商品分页查询")
    public Result<PageResult> page(GoodPageQueryDTO goodPageQueryDTO) {
        log.info("商品分页查询:{}", goodPageQueryDTO);
        PageResult pageResult = goodService.pageQuery(goodPageQueryDTO);//后绪步骤定义
        return Result.success(pageResult);
    }

    /**
     * 商品批量删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("商品批量删除")
    public Result delete(@RequestParam List<Long> ids) {
        log.info("商品批量删除：{}", ids);
        goodService.deleteBatch(ids);//后绪步骤实现
        return Result.success();
    }

    /**
     * 根据id查询商品
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询商品")
    public Result<GoodVO> getById(@PathVariable Long id) {
        log.info("根据id查询商品：{}", id);
        GoodVO goodVO = goodService.getByI(id);//后绪步骤实现
        return Result.success(goodVO);
    }
}
